<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>列表</title>
  <meta name="renderer" content="webkit" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
  <link rel="stylesheet" href="../../static/lib/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="../../static/css/admin.css" media="all" />
</head>

<body>
  <div id="TMM_app">
    <div class="layui-fluid">
      <div class="layui-card">
        <div class="layui-tab layui-tab-brief tmm-table-tab" lay-filter="component-tabs-brief">
          <ul class="layui-tab-title" id="ustatus">
            <li status="0" id="status0" class="layui-this"></li>
            <li status="1" id="status1"></li>
            <li status="2" id="status2"></li>
          </ul>
          <div class="layui-tab-content">
          </div>
        </div>
        <div class="layui-form layui-card-header tmm-admin-card-header-auto tmm-filter-form">
          <input type="hidden" id="statusInput"/>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">手机号码</label>
              <div class="layui-input-inline">
                <input type="text" name="mobile" id="mobile" placeholder="手机号码" autocomplete="off" class="layui-input" />
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">用户id</label>
              <div class="layui-input-inline">
                <input type="text" name="uid" id="uid" placeholder="用户id" autocomplete="off" class="layui-input" />
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label" style="width: 70px;">用户状态</label>
              <div class="layui-input-inline">
                <select name="status" id="status">
                  <option value="-1">全部</option>
                  <option value="0">正常</option>
                  <option value="1">注销</option>
                  <option value="2">禁用</option>
                </select>
              </div>
            </div>

            <div class="layui-inline">
              <button class="layui-btn tmm-admin-btn-list" lay-submit="" id="query" lay-filter="LAY-app-contlist-search">
                搜索
              </button>
            </div>
          </div>
        </div>
        <div class="layui-card-body">

          <table id="tmm-doctors-table" lay-filter="tmm-doctors" class="layui-table"></table>
        </div>
      </div>
    </div>
  </div>

  <script src="../../static/lib/layui/layui.js"></script>
  <script>
    layui
      .config({
        base: "../../static/js/"
      })
      .extend({
        index: "index"
      })
      .use(["index", "table", "laydate"], function () {
        var $ = layui.$,
          admin = layui.admin,
          view = layui.view,
          table = layui.table,
          form = layui.form;
          laydate = layui.laydate,

          laydate.render({
            elem: "#time",
            type:'datetime'
          });



        $(".layui-btn.tmm-admin-btn-tags").on("click", function () {
          var type = $(this).data("type");
          active[type] ? active[type].call(this) : "";
        });

        table.render({
          elem: "#tmm-doctors-table",
          skin: 'nob',
          size: 'lg',
          height: 'full-280',
          even: true,
          page: true,
          limit: 10,
          limits: [10, 20, 50],
          url: "${path}/app/user/list",
          where:{
            mobile:$("#mobile").val(),
              status:$("#status").val(),
              id:$("#uid").val()
          },
          cols: [[
            {field:'id',title: 'ID', width:'6%'},
            {field:'amount',title: '余额', width:'7%'},
            {field:'nickName',title: '昵称', width:'7%'},
            {field:'avatarUrl', title: '头像',width:'5%',templet:function (d) {
                var html ='暂无图片';
                if(d.avatarUrl!=null && d.avatarUrl!=''){
                  html = '<img src="'+d.avatarUrl+'" style="height: 40px;"/>';
                }
                return html;
              }},
            {field:'phone', width:'10%',title: '电话'},
            {field:'realName',width:'6%', title: '真实名称'},
            {field:'realIdCard', width:'14%',title: '证件号码'},
            {field:'merchantNo', width:'12%',title: '商户号'},
            {field:'isBlack', title: '拉黑',width:"5%",templet:function (d) {
                var html ='否';
                if(d.isBlack==1){
                  html = '是';
                }
                return html;
              }},
            {field:'account_status', title: '状态/群主',width:"9%",templet:function (d) {
                var html ='正常';
                if(d.account_status==1){
                  html = '注销';
                }
                if(d.account_status==2){
                  html = '禁用';
                }
                var html1 ='开起';
                if(d.groupApplyStatus==0){
                  html1 = '未开起';
                }
                return html+"/"+html1;
              }},
              {field:'create_time', title: '创建时间',width:"9%",templet:function (d) {
                  if(d.create_time!=null && d.create_time!=''){
                      return d.create_time.substring(0,19)
                  }
                  return "无";
              }},
            {field:'id', title: '操作',width:"20%",height:"120px;",templet:function (d) {
                var html = '';
                html +=  '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="syncMoney">同步余额</a>';
                if(d.groupApplyStatus==0){
                  html +=  '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="groupApplyStatus">开启群主</a>';
                }else if(d.groupApplyStatus==1){
                  html +=  '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="groupApplyStatusClose">关闭群主</a>';
                }
                return html;
              }},
            ]],
          done: function(res, curr, count){
              $(".layui-table-main  tr").each(function (index ,val) {
                  $($(".layui-table-fixed .layui-table-body tbody tr")[index]).height($(val).height());
              });
          },
          text:{none:"暂无数据"},
        });
        table.on("tool(tmm-doctors)", function (t) {
          var n = t.data;
          switch (t.event){
              case 'syncMoney':
                layer.confirm("是否同步账户金额", function (e) {
                  var index = layer.load(2);
                  $.ajax({
                    type:"post",
                    url:"${path}/app/user/sync/money",
                    dataType:"json",
                    data:{id:n.id},
                    success:function(data){
                      layer.close(index);
                      if(data.code ==0){
                        layer.open({
                          type: 1,
                          shade: 0.8,
                          offset: 'auto',
                          shadeClose: true,//点击外围关闭弹窗
                          scrollbar: false,//不现实滚动条
                          title: "同步信息", //不显示标题
                          area: ['40%', '45%'],
                          content: "<div style='display:flex;justify-content:center;'>" +
                                  "<textarea id='refundAddress' style='width:80%;height:60px;margin-top: 8px'> " +
                                  " 提示："+data.msg+" \n " +
                                  " 原有余额："+data.balance+"\n " +
                                  " 同步金额："+data.cashAmount+"</textarea>" +
                                  "</div>",
                          btn:['确认'],
                          btnAlign:'c',
                          yes: function (index,layero) {
                            location.reload();
                          }
                        // layer.alert(data.msg,{icon:1}, function(){
                        //   location.reload();
                        // });
                        });
                      }else{
                        layer.alert(data.msg,{icon:2});
                      }
                    },
                    error:function (data) {
                      layer.close(index);
                    }
                  });
                })
                  return;
              case 'groupApplyStatusClose':
                layer.confirm("是否关闭群主", function (e) {
                  var index = layer.load(2);
                  $.ajax({
                      type:"post",
                      url:"${path}/app/user/group/apply/status",
                      dataType:"json",
                      data:{id:n.id,status:0},
                      success:function(data){
                          layer.close(index);
                          if(data.code ==0){
                              layer.alert(data.msg,{icon:1}, function(){
                                  location.reload();
                              });
                          }else{
                              layer.alert(data.msg,{icon:2});
                          }
                      },
                      error:function (data) {
                          layer.close(index);
                      }
                  });
                })
                return;
            case 'groupApplyStatus':
              layer.confirm("是否开起群主", function (e) {
                var index = layer.load(2);
                $.ajax({
                  type:"post",
                  url:"${path}/app/user/group/apply/status",
                  dataType:"json",
                  data:{id:n.id,status:1},
                  success:function(data){
                    layer.close(index);
                    if(data.code ==0){
                      layer.alert(data.msg,{icon:1}, function(){
                        location.reload();
                      });
                    }else{
                      layer.alert(data.msg,{icon:2});
                    }
                  },
                  error:function (data) {
                    layer.close(index);
                  }
                });
              })
              return;
          }
        });
        //查询
        $('#query').on('click', function(){
            table.reload('tmm-doctors-table', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    mobile:$("#mobile").val(),
                    status:$("#status").val(),
                    id:$("#uid").val()
                }
            }, 'data');
        });
      });
  </script>
</body>

</html>